import 'package:qgchat/http/io.dart';
import 'package:qgchat/http/models/anchorModel.dart';
import 'package:qgchat/http/models/giftlistModel.dart';
import 'package:qgchat/http/models/innerpageModel.dart';
import 'package:qgchat/http/models/invitationInfoModel.dart';
import 'package:qgchat/http/models/listuserInfoModel.dart';
import 'package:qgchat/http/models/shortVideoModel.dart';
import 'package:qgchat/http/models/taglistModel.dart';
import 'package:qgchat/http/models/tokenuserInfoModel.dart';

class VideoApis {
  /// 视频前检测主播状态
  static Future checkVideoStatus(String targetToken) async {
    return await Io.get(
      "member/checkVideoStatus",
      data: {"token": targetToken},
    );
  }

  /// 回拨前检测用户状态
  static Future checkCallStatus(String targetToken) async {
    return await Io.get("member/checkCallStatus", data: {"token": targetToken});
  }

  /// 预约主播
  static Future appointment(String targetToken) async {
    return await Io.post(
      "appointment/appointment",
      data: {"other": targetToken},
    );
  }

  /// token获取用户信息
  static Future tokenuserInfo(String targetToken) async {
    Map result = await Io.get("member/tokenuserInfo", data: {
      "member_token": targetToken,
    });
    if (_checkResult(result) && result['data'] != null) {
      return TokenuserInfoModel.fromJson(result['data']);
    } else {
      return TokenuserInfoModel();
    }
  }

  /// 获取用户在该主播的消费
  static Future listuserInfo(String anchorToken, String memberToken) async {
    Map result = await Io.get("member/ListuserInfo", data: {
      "anchor_token": anchorToken,
      "member_token": memberToken,
    });
    if (_checkResult(result) && result['data'] != null) {
      return ListuserInfoModel.fromJson(result['data']);
    } else {
      return ListuserInfoModel();
    }
  }

  /// 通话信息
  static Future invitationInfo(int inv) async {
    Map result = await Io.get("invitation/invitationInfo", data: {"id": inv});
    if (_checkResult(result) && result['data'] != null) {
      return InvitationInfoModel.fromJson(result['data']);
    } else {
      return InvitationInfoModel();
    }
  }

  /// 礼物列表
  static Future giftlist() async {
    Map result = await Io.get("setting/giftlist");
    if (_checkResult(result)) {
      return result['data'].map<GiftlistModel>((item) {
        return GiftlistModel.fromJson(item);
      }).toList();
    } else {
      return List<GiftlistModel>();
    }
  }

  /// 赠送主播礼物(日常赠送或者直播)
  static Future sendGift(int id, int number, String token) async {
    return await Io.post("gift/sendGift", data: {
      "id": id,
      "number": number,
      "token": token,
    });
  }

  /// 获取视频每周土豪榜
  static Future getvideotycool(int id) async {
    Map result = await Io.get("vedio/vedioList", data: {
      "vedio_id": id,
    });
    if (_checkResult(result)) {
      return result['data'].map<Closeman>((item) {
        return Closeman.fromJson(item);
      }).toList();
    } else {
      return List<Closeman>();
    }
  }

  /// 获取小视频信息
  static Future getvideoinfo(int id) async {
    Map result = await Io.get("vedio/vedioInfo", data: {
      "vedio_id": id,
    });
    if (_checkResult(result) && result['data'] != null) {
      return InnerpageModel.fromJson(result['data']);
    } else {
      return InnerpageModel();
    }
  }

  /// 小视频赠送礼物(观看的小视频，不是直播时送礼物)
  static Future gifVedio(int id, int number, String token, int vid) async {
    return await Io.post("vedio/gifVedio", data: {
      "gid": id,
      "number": number,
      "member_token": token,
      "vedio_id": vid,
    });
  }

  /// 小视频点击喜欢
  static Future clicklove(int id) async {
    return await Io.post("vedio/clicklike", data: {
      "vedio_id": id,
    });
  }

  /// 小视频取消喜欢
  static Future canclelove(int id) async {
    return await Io.post("vedio/cancellike", data: {
      "vedio_id": id,
    });
  }

  /// 热门小视频
  static Future popluar({int page, int limit}) async {
    Map result =
        await Io.get("vedio/hot_vedio", data: {'page': page, 'limit': limit});
    if (_checkResult(result)) {
      return result['data'].map<ShortVideoModel>((item) {
        return ShortVideoModel.fromJson(item);
      }).toList();
    } else {
      return List<ShortVideoModel>();
    }
  }

  /// 关注的主播小视频
  static Future focusvideo({int page, int limit}) async {
    Map result = await Io.get("vedio/followManVedio",
        data: {'page': page, 'limit': limit});
    if (_checkResult(result)) {
      return result['data'].map<ShortVideoModel>((item) {
        return ShortVideoModel.fromJson(item);
      }).toList();
    } else {
      return List<ShortVideoModel>();
    }
  }

  /// 最新小视频
  static Future newest({int page, int limit}) async {
    Map result =
        await Io.get("vedio/new_vedio", data: {'page': page, 'limit': limit});
    if (_checkResult(result)) {
      return result['data'].map<ShortVideoModel>((item) {
        return ShortVideoModel.fromJson(item);
      }).toList();
    } else {
      return List<ShortVideoModel>();
    }
  }

  // 举报主播
  static Future reportAnthor(userToken,content) async {
    Map result = await Io.post("member/user_info",data: {
      'touser_id':userToken,
      'content':content
    });
    return result;
  }

  /// 评价标签列表
  static Future taglist() async {
    Map result = await Io.get("member/taglist");
    if (_checkResult(result)) {
      return result['data'].map<TaglistModel>((item) {
        return TaglistModel.fromJson(item);
      }).toList();
    } else {
      return List<TaglistModel>();
    }
  }

  /// 用户评价主播
  static Future commentZhubo(int zhuboId, List<int> xingxiangId) async {
    return await Io.post("member/comment_zhubo", data: {
      "zhubo_id": zhuboId,
      "xingxiang_id": xingxiangId,
    });
  }

  /// 改变回拨状态
  static Future callback(int id) async {
    return await Io.get("appointment/callback", data: {"id": id});
  }
}

/// 检测回调数据是否可用
_checkResult(res) {
  return res != null && res['status'] == 1;
}
